[Lab3 – Modify br2-external-tree and Rebuild the Buildroot]
----------------------------------------------------------------
----------------------------------------------------------------
/* Create configurations for Hobby Kit in BR2-External Project. */
----------------------------------------------------------------

/* Execute Commands on Host PC */
cd ~/Linux4MCHP/buildroot-external-microchip/
cp -r board/microchip/sam9x60_curiosity/ board/microchip/sam9x60_hobby/

----------------------------------------------------------------
----------------------------------------------------------------

/* Change OS Image Name to Hobby Kit */
/* Execute Commands on Host PC */
code ~/Linux4MCHP/buildroot-external-microchip/board/microchip/sam9x60_hobby/genimage.cfg

----------------------------------------------------------------

/* Modify the genimage.cfg*/
image boot.vfat {
    vfat {
        files = {
            "sam9x60_hobby.itb",
            "boot.bin",
            "u-boot.bin"
        }
        ...
    }
    ...
}

image sdcard-hobby.img {
    ...
}

----------------------------------------------------------------
----------------------------------------------------------------

/* Change the uboot-env.txt content. */
/* Execute Commands on Host PC */
code ~/Linux4MCHP/buildroot-external-microchip/board/microchip/sam9x60_hobby/uboot-env.txt

----------------------------------------------------------------

/* Modify the uboot-env.txt*/

...
/* Modify the board_name*/
board_name=sam9x60_hobby
...

----------------------------------------------------------------


----------------------------------------------------------------
----------------------------------------------------------------
/* Create and Modify the Device-Tree-Source for Hobby Kit in Buildroot External */ 
----------------------------------------------------------------

/* Execute Commands on Host PC */
cd ~/Linux4MCHP/buildroot-external-microchip/board/microchip/sam9x60_hobby
mkdir -p dts/linux/microchip/
cp ~/Linux4MCHP/buildroot-mchp/output/build/linux-custom/arch/arm/boot/dts/microchip/at91-sam9x60_curiosity.dts dts/linux/microchip/at91-sam9x60_hobby.dts

----------------------------------------------------------------


----------------------------------------------------------------
----------------------------------------------------------------
/* Use the menu to configure Buildroot. */
----------------------------------------------------------------

/* Execute Commands on Host PC */
cd ~/Linux4MCHP/buildroot-mchp
make menuconfig

----------------------------------------------------------------

/* Modify the Login Welcome Message for SAM9X60 Hobby Kit */
( [Buildroot] --> [System configuration] --> [System banner] )
Welcome to the Microchip SAM9X60 Hobby Kit

/* Modify the System hostname for SAM9X60 Hobby Kit */
( [Buildroot] --> [System configuration] --> [System hostname] )
sam9x60_hobby

/* Modify the custom scripts location of genimage.cfg */
( [Buildroot] --> [System configuration] -->  [Extra arguments passed to custom scripts] )
-c $(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sam9x60_hobby/genimage.cfg

----------------------------------------------------------------

/* Modify the U-boot env Source location of genimage.cfg */
( [Buildroot] --> [Host utilities] -->  [Source files for environment] )
$(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sam9x60_hobby/uboot-env.txt

----------------------------------------------------------------

/* Modify the Device-Tree-Source File Name for SAM9X60 Hobby Kit for Next Step */
( [Buildroot] --> [Kernel] -->  [In-tree Device Tree Source file names] )
microchip/at91-sam9x60_hobby

/* Modify the Out-of-tree Device Tree Source overlay directories for SAM9X60 Hobby Kit */
( [Buildroot] --> [Kernel] -->  [Out-of-tree Device Tree Source overlay directories] )
$(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sam9x60_hobby/dts/linux

----------------------------------------------------------------

/* Modify the Platform Name of dt-overlay-mchp for SAM9X60 Hobby Kit */
( [Buildroot] --> [External options] -->  [platform name] )
sam9x60_hobby

----------------------------------------------------------------

/* Modify the Patches Location in Buildroot External */
( [Buildroot] --> [Build options] -->  [global patch and hash directories] )
$(BR2_EXTERNAL_MCHP_PATH)/patches $(BR2_EXTERNAL_MCHP_PATH)/board/microchip/sam9x60_hobby/patches

----------------------------------------------------------------
----------------------------------------------------------------

/* Create directory for patches for linux4microchip (Must be done before executing 'make savedefconfig') */
/* Execute Commands on Host PC */
mkdir -p ~/Linux4MCHP/buildroot-external-microchip/board/microchip/sam9x60_hobby/patches/dt-overlay-mchp/linux4microchip-2025.04

----------------------------------------------------------------
----------------------------------------------------------------

/* Save the configuration of SAM9X60 Hobby Kit to Buildroot External. */
/* Execute Commands on Host PC */
cd ~/Linux4MCHP/buildroot-mchp
make savedefconfig BR2_DEFCONFIG=~/Linux4MCHP/buildroot-external-microchip/configs/sam9x60_hobby_graphics_defconfig

----------------------------------------------------------------


----------------------------------------------------------------
----------------------------------------------------------------
/* Prepared the materials to make Image-Tree-Blob for Hobby Kit. */
----------------------------------------------------------------

/* Reset the dt-overlay-mchp in Buildroot. */
/* Execute Commands on Host PC */
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
cd ~/Linux4MCHP/buildroot-mchp
make dt-overlay-mchp-dirclean
make dt-overlay-mchp-extract

----------------------------------------------------------------
----------------------------------------------------------------

/* Prepared the materials */
/* Execute Commands on Host PC */
rm -rf ~/Linux4MCHP/Projects/Patches
mkdir -p ~/Linux4MCHP/Projects/Patches/
mv ./output/build/dt-overlay-mchp-linux4microchip-2025.04/ ~/Linux4MCHP/Projects/Patches/dt-overlay-mchp/
cd ~/Linux4MCHP/Projects/Patches/dt-overlay-mchp/
git config --global user.email "you@example.com"
git config --global user.name "Your Name"
git init
git add Makefile
git add sam9x60_hobby.its
git commit -m "original"
git log
cp sam9x60_curiosity.its sam9x60_hobby.its

----------------------------------------------------------------
----------------------------------------------------------------

/* Modify "sam9x60_hobby.its" in dt-overlay-mchp*/
/* Execute Commands on Host PC */
code ~/Linux4MCHP/Projects/Patches/dt-overlay-mchp/sam9x60_hobby.its

----------------------------------------------------------------

/ {
    description = "Microchip SAM9X60-Hobby FIT Image";
    ...

    images {

        ...

        base_fdt {
            description = "SAM9X60-Hobby Flattened Device Tree blob";
            data = /incbin/("./at91-sam9x60_hobby.dtb");
            ...
        };

        /*!! Remove it !!*/ 
        fdt_pda5 {
            ...
        };

        /*!! Remove it !!*/ 
        fdt_wilc3000 {
            ...
        };
    };

    configurations {
        ...
        kernel_dtb {
            description = "Linux kernel and base FDT blob for SAM9X60-Hobby board";
            ...
        };

        base_dtb {
            description = "Base FDT blob for SAM9X60-Hobby board";
            ...
        };

        /*!! Remove it !!*/ 
        pda5 {
            ...
        };

        /*!! Remove it !!*/ 
        wilc {
            ...
        };
    };
};

----------------------------------------------------------------
----------------------------------------------------------------

/* Modify "Makefile" in dt-overlay-mchp */
/* Execute Commands on Host PC */
code ~/Linux4MCHP/Projects/Patches/dt-overlay-mchp/Makefile

----------------------------------------------------------------

BDIR?=sam9x60_hobby sam9x60ek sama5d29_curiosity sama5d27_som1_ek sama5d27_wlsom1_ek sama5d2_icp sama5d2_ptc_ek sama5d2_xplained sama5d2_xplained_grts sama5d3_xplained sama5d3_eds sama5d4_xplained sama7g5ek sam9x60_curiosity sam9x75eb mpfs_icicle mpfs_icicle_amp mpfs_video

...

SAM9X60_CURIOSITY_DTBO_OBJECTS:= $(patsubst %.dtso,%.dtbo,$(wildcard sam9x60_curiosity/*.dtso))
SAM9X60_HOBBY_DTBO_OBJECTS:= $(patsubst %.dtso,%.dtbo,$(wildcard sam9x60_hobby/*.dtso))

...

sam9x60_curiosity_dtbos: $(SAM9X60_CURIOSITY_DTBO_OBJECTS)

sam9x60_hobby_dtbos: $(SAM9X60_HOBBY_DTBO_OBJECTS)

----------------------------------------------------------------
----------------------------------------------------------------

/* Make a difference patch after modifying dt-overlay-mchp and place it in the Buildroot External directory of the SAM9X60 Hobby Kit. */
cd ~/Linux4MCHP/Projects/Patches/dt-overlay-mchp
git add Makefile
git add sam9x60_hobby.its
git commit -m "hobby"
git log
git format-patch -1
cp ./0001-hobby.patch ~/Linux4MCHP/buildroot-external-microchip/board/microchip/sam9x60_hobby/patches/dt-overlay-mchp/linux4microchip-2025.04/

----------------------------------------------------------------


----------------------------------------------------------------
----------------------------------------------------------------
/* Rebuild the Buildroot for Hobby Kit using the configuration and Buildroot External for SAM9X60 Hobby Kit. */
----------------------------------------------------------------

/* Execute Commands on Host PC */
export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
cd ~/Linux4MCHP/buildroot-mchp
make at91bootstrap3-dirclean
make host-uboot-tools-dirclean
make uboot-dirclean
make linux-dirclean
make dt-overlay-mchp-dirclean
BR2_EXTERNAL=../buildroot-external-microchip/ make sam9x60_hobby_graphics_defconfig
make
ls -l ./output/images

----------------------------------------------------------------
----------------------------------------------------------------

/* View the modified section of heartbeat triger in the Device-Tree */
/* Execute Commands on EVB */
ls /proc/device-tree/leds/led-blue/
ls /proc/device-tree/leds/led-green/
cat /proc/device-tree/leds/led-green/linux,default-trigger

----------------------------------------------------------------
----------------------------------------------------------------

/* Reboot Linux system to show the Welcome Message */
/* Execute Commands on EVB */
reboot

----------------------------------------------------------------